package model;

import java.util.List;
import java.util.Map;

import model.Dbuit;
import model.PageTools;

public class FoodDesk {
		
	public Integer getTableCount(String typeid) throws Exception{
		 String sql="select count(rowid) as cr from food t where t.typeid like '%"+typeid+"%'";
	        List<Map> result=Dbuit.query(sql);
	        return Integer.parseInt(result.get(0).get("CR").toString());
	}
	
	public PageTools getTablePage(String typeid,Integer curPage) throws Exception{
		
		Integer totalCount=getTableCount(typeid);
	       PageTools pt=new PageTools(curPage, totalCount, 6);
	       StringBuffer sb=new StringBuffer();
	       String sql="select * from (select t.*,ft.typename,rownum rn from food t inner join foodtype ft on t.typeid=ft.typeid where t.typeid like '%"+typeid+"%')"
	               + " where rn>="+pt.getStartIndex()+" and rn<="+pt.getEndIndex();
	       List<Map> result=Dbuit.query(sql);
	       pt.setData(result);
	       return pt;
	}

}
